package day15.socketdemo06;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @author Xiao
 * @date 2021/8/9
 */
public class ServerDemo06 {
    /**
     * 需求：
     * 客户端：发送数据，接收服务器反馈；
     * 服务器：接收数据，给出反馈。
     */
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        Socket so = ss.accept();
        InputStream is = so.getInputStream();
        int read;
        while ((read = is.read()) != -1) {
            System.out.print((char) read);
        }
        System.out.println();
        OutputStream os = so.getOutputStream();
        //os.write("服务器收到，Over!".getBytes());
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
        bw.write("服务器收到，Over!");
        bw.newLine();
        bw.flush();
        bw.close();
        os.close();
        so.close();
        ss.close();
    }
}
